package com.ztgf.shopping.api.client.epg;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.epg.EpgShopSectionBO;
import com.ztgf.shopping.models.dto.epg.EpgShopSectionDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.epg.IEpgShopBannerService;
import com.ztgf.shopping.models.bo.epg.EpgShopBannerBO;
import com.ztgf.shopping.models.dto.epg.EpgShopBannerDTO;

import java.util.List;

/**
 * 店铺页banner控制器
 *
 * @author YUE
 * @Date 2020-05-28 18:38:51
 */

@RestController
@RequestMapping("/api/epgShopBanner")
@Slf4j
@Api(value = "EpgShopBannerApiController",tags = "店铺页bannerApi接口")
public class EpgShopBannerApiController {

    @DubboReference
    private IEpgShopBannerService epgShopBannerService;

    /**
     * 店铺banner 根据功能id
     * @param moduleId 功能id
     * @return
     */
    @ApiOperation(value = "店铺banner 根据功能id",notes = "店铺banner 根据功能id")
    @PostMapping("/getListByModuleId")
    public Result<List<EpgShopBannerDTO>> getListByModuleId(Long moduleId){
        EpgShopBannerBO epgShopBannerBO = new EpgShopBannerBO();
        epgShopBannerBO.setModuleId(moduleId);
        List<EpgShopBannerDTO> epgSectionDTOList = epgShopBannerService.getBySelectShopBannerInfoNoPage(epgShopBannerBO);
        return new Result<>(epgSectionDTOList);
    }

    /**
     * 根据店铺id查询商品详情的banner
     * @param shopId
     * @return
     */
    @PostMapping("/getShopAdvertisementBanner")
    @ApiOperation(value = "根据店铺id获取商品详情页的banner",notes = "根据店铺id获取商品详情页的banner")
    public Result<List<EpgShopBannerDTO>> getShopAdvertisementBanner(Long shopId){
        if(null == shopId){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        List<EpgShopBannerDTO> epgShopBannerDTOList = epgShopBannerService.getShopAdvertBannerListByShopId(shopId);
        return new Result<>(epgShopBannerDTOList);
    }


    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<EpgShopBannerDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        EpgShopBannerDTO dto = epgShopBannerService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺页banner列表",notes = "店铺页banner列表")
    @PostMapping("/querySelectPageList")
    public Result<List<EpgShopBannerDTO>> querySelectPageList(EpgShopBannerBO bo){
        if(null == bo)
            return new Result<>(CodeEnum.FAIL_100002 );
        List<EpgShopBannerDTO> epgShopBannerDTOList = epgShopBannerService.getBySelectShopBannerInfoNoPage(bo);
        return new Result<>(epgShopBannerDTOList);
    }
}
